local sushou = fk.CreateSkill {
    name = "gai__sushou",
  }
  
  Fk:loadTranslationTable{
    ["gai__sushou"] = "夙守",
    [":gai__sushou"] = "一名角色的出牌阶段开始时，若其手牌数是全场唯一最多的，你可以失去1点体力并摸X张牌。若此时不是你的回合内，你观看"..
    "当前回合角色一半数量的手牌（向下取整），你可以用至多Y张手牌替换其中等量的牌。（X为你的体力值,Y为你已损失的体力值）",
  
    ["#sushou-invoke"] = "夙守：你可以失去1点体力并摸牌，与 %dest 交换手牌",
    ["#sushou-exchange"] = "夙守：与 %dest 交换至多%arg张手牌",
  
    ["$gai__sushou1"] = "敌众我寡，怎可少谋？",
    ["$gai__sushou2"] = "临城据守，当出奇计。",
  }
  
  Fk:addPoxiMethod{
    name = "gai__sushou",
    card_filter = function(to_select, selected, results, origCards)
      if #selected > 0 then
        local isBottom = table.contains(results[2], selected[1])
        local canSwap = {}
        if isBottom then
          canSwap = table.filter(results[1], function(id) return not table.contains(origCards[1], id) end)
        else
          canSwap = table.filter(results[2], function(id) return not table.contains(origCards[2], id) end)
        end
  
        if #canSwap >= Self:getLostHp() then
          return table.contains(canSwap, to_select)
        end
      end
  
      return true
    end,
    feasible = Util.TrueFunc,
  }
  
  sushou:addEffect(fk.EventPhaseStart, {
    anim_type = "support",
    can_trigger = function(self, event, target, player, data)
      return player:hasSkill(sushou.name) and target.phase == Player.Play and
        player.hp > 0 and not target.dead and
        table.every(player.room.alive_players, function (p)
          return p == target or p:getHandcardNum() < target:getHandcardNum()
        end)
    end,
    on_cost = function(self, event, target, player, data)
      local room = player.room
      if room:askToSkillInvoke(player, {
        skill_name = sushou.name,
        prompt = "#sushou-invoke::" .. target.id,
      }) then
        event:setCostData(self, {tos = {target}})
        return true
      end
    end,
    on_use = function(self, event, target, player, data)
      local room = player.room
      room:loseHp(player, 1, sushou.name)
      if player.dead then return end
      local x = player.hp  -- 修改这里：将getLostHp()改为hp，获取当前体力值
      if x > 0 then
        player:drawCards(x, sushou.name)
      end
      if target == player or target.dead or target:getHandcardNum() < 2 then return end
      local cards = table.random(target:getCardIds("h"), target:getHandcardNum() // 2)
      local lostHp = player:getLostHp()  -- 这里保持原样，第二个X还是已损失体力值
      local results = room:askToArrangeCards(player, {
        skill_name = sushou.name,
        card_map = {
          target.general, cards,
          player.general, player:getCardIds("h"),
        },
        poxi_type = "gai__sushou",
        prompt = "#sushou-exchange::" .. target.id .. ":" .. lostHp,
        cancelable = true,
      })
      local cards1 = table.filter(results[1], function (id)
        return table.contains(player:getCardIds("h"), id)
      end)
      local cards2 = table.filter(results[2], function (id)
        return table.contains(cards, id)
      end)
      if #cards1 > 0 then
        room:moveCardTo(cards1, Card.PlayerHand, target, fk.ReasonExchange, sushou.name, nil, false, player)
      end
      if #cards2 > 0 then
        room:moveCardTo(cards2, Card.PlayerHand, player, fk.ReasonExchange, sushou.name, nil, false, player)
      end
    end,
  })
  
  return sushou